package com.knowledgepoint.study.config.mybatis;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class PhysicalDeleteById extends AbstractMethod {
    
    public PhysicalDeleteById() {
        super("physicalDeleteById");
    }
    
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        String sql = "DELETE FROM %s WHERE %s=#{%s}";
        String tableName = tableInfo.getTableName();
        String keyColumn = tableInfo.getKeyColumn();
        String keyProperty = tableInfo.getKeyProperty();
        String sqlResult = String.format(sql, tableName, keyColumn, keyProperty);
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sqlResult, modelClass);
        return this.addDeleteMappedStatement(mapperClass, "physicalDeleteById", sqlSource);
    }
}
